﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using client.Settings;
using System.Diagnostics;

namespace client.Managers
{
    class Serialization
    {
       public static void serializationPref(ConfigSettings conf)
        {
            try{
            FileStream stream = new FileStream("app.set", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            BinaryFormatter formater = new BinaryFormatter();
            formater.Serialize(stream, conf);
            stream.Close();
            }
            catch(NullReferenceException ex)
            {}

        }
        public static ConfigSettings deserializationPref(ConfigSettings conf)
        {
            try
            {
                FileStream stream = new FileStream("app.set", FileMode.Open, FileAccess.ReadWrite);
                BinaryFormatter formater = new BinaryFormatter();
                conf = (ConfigSettings)formater.Deserialize(stream);
                stream.Close();
            }
            catch (FileNotFoundException ex)
            { }
            catch (Exception ex)
            {
                Debugger.Break();
            }
            return conf;
        }
       
    }
}
